/**
 * Yolema.com Inc.
 * Copyright (c) 2011-2012 All Rights Reserved.
 */
package org.grayrabbit.pay.core.action.transaction;

import java.util.Date;
import java.util.Map;

import org.grayrabbit.web.struts2.GenericAction;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.InterceptorRef;
import org.apache.struts2.convention.annotation.InterceptorRefs;
import org.grayrabbit.pay.core.model.results.GenericsResult;
import org.apache.struts2.convention.annotation.Results;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.grayrabbit.pay.core.model.pages.PageList;
import org.grayrabbit.pay.core.model.entity.system.AppSystem;
import org.grayrabbit.pay.core.model.entity.system.TradeTerminal;
import org.grayrabbit.pay.core.model.entity.transaction.Trade;
import org.grayrabbit.pay.core.model.enums.TradeEnum;
import org.grayrabbit.pay.core.biz.manager.system.AppSystemManager;
import org.grayrabbit.pay.core.biz.manager.system.TradeTerminalManager;
import org.grayrabbit.pay.core.biz.manager.transaction.TradeManager;

/**
 * 
 * 
 * @author liyd
 * @version $Id: TradeAction.java, v 0.1 Fri Jun 01 11:16:04 CST 2012 liyd Exp $
 */
@Results({ @Result(name = GenericAction.RELOAD, location = "trade_list", type = "redirectAction"),
          @Result(name = GenericAction.INPUT, location = "trade-input.vm"),
          @Result(name = GenericAction.LIST, location = "transaction/trade-list.vm") })
@InterceptorRefs({ @InterceptorRef(value = "token", params = { "includeMethods", "save" }),
                  @InterceptorRef("login"), @InterceptorRef("defaultStack") })
public class TradeAction extends GenericAction {

    /** serialVersionUID */
    private static final long          serialVersionUID = 4504508267038067483L;

    /** 业务对象manager接口 */
    @Autowired
    private TradeManager               tradeManager;

    @Autowired
    private AppSystemManager           appSystemManager;

    @Autowired
    private TradeTerminalManager       tradeTerminalManager;

    /** 业务实体对象 */
    private Trade                      trade            = new Trade();
    private Date                       startDate;
    private Date                       endDate;

    /** 业务实体对象列表 */
    private PageList<Trade>            tradeList;

    private Map<String, AppSystem>     appMap;
    private Map<String, TradeTerminal> terminalMap;

    /**
     * 查询列表
     * 访问URL /trade_list.action
     * 
     * @return
     */
    @Action(value = "trade_list")
    public String list() {
        GenericsResult<PageList<Trade>> result = tradeManager.queryPageList(trade, startDate,
            endDate);
        GenericsResult<Map<String, AppSystem>> appResult = appSystemManager.findAllMap();
        GenericsResult<Map<String, TradeTerminal>> terminalResult = tradeTerminalManager
            .findAllMap();

        if (!result.isSuccess()) {
            this.addActionError(result.getResultMsg());
        }
        if (!appResult.isSuccess()) {
            this.addActionError(appResult.getResultMsg());
        }
        if (!terminalResult.isSuccess()) {
            this.addActionError(terminalResult.getResultMsg());
        }
        terminalMap = terminalResult.getResultData();
        appMap = appResult.getResultData();
        tradeList = result.getResultData();
        return LIST;
    }

    /**
     * Getter method for property <tt>trade</tt>.
     * 
     * @return property value of trade
     */
    public Trade getTrade() {
        return trade;
    }

    /**
     * Setter method for property <tt>trade</tt>.
     * 
     * @param trade value to be assigned to property trade
     */
    public void setTrade(Trade trade) {
        this.trade = trade;
    }

    /**
     * Getter method for property <tt>tradeList</tt>.
     * 
     * @return property value of tradeList
     */
    public PageList<Trade> getTradeList() {
        return tradeList;
    }

    /**
     * Setter method for property <tt>tradeList</tt>.
     * 
     * @param districtList value to be assigned to property tradeList
     */
    public void setTradeList(PageList<Trade> tradeList) {
        this.tradeList = tradeList;
    }

    public Date getStartDate() {
        return startDate;
    }

    public void setStartDate(Date startDate) {
        this.startDate = startDate;
    }

    public Date getEndDate() {
        return endDate;
    }

    public void setEndDate(Date endDate) {
        this.endDate = endDate;
    }

    public Map<String, TradeTerminal> getTerminalMap() {
        return terminalMap;
    }

    public void setTerminalMap(Map<String, TradeTerminal> terminalMap) {
        this.terminalMap = terminalMap;
    }

    public Map<String, AppSystem> getAppMap() {
        return appMap;
    }

    public void setAppMap(Map<String, AppSystem> appMap) {
        this.appMap = appMap;
    }

    public TradeEnum[] getTradeEnums() {
        return TradeEnum.values();
    }

}
